package com.star.spring.reactor.flux;


import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;

import java.util.function.Function;

/**
 * @description: map
 * @author: star
 * @create: 2025-03-14 09:29
 **/

public class FlatAndMap {

    public static void main(String[] args) {

        // Function<? super T, ? extends V> mapper
        Flux<String> just = Flux.just("hello", ",", "world");
        Function<String, Flux<String>> mapper = s -> Flux.just(s.toUpperCase());
        just
                .map(mapper)
                .subscribe((System.out::println));


        System.out.println("============================");


        // Function<? super T, Publisher<? extends R>> mapper
        Function<String, Publisher<String>> mapperPublisher = s -> Flux.just(s.toUpperCase().split(""));
        just.flatMap(mapperPublisher).subscribe((item -> {
            System.out.println(item);
        }));
    }
}
